package com.shop.storage.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shop.common.log.annotation.Log;
import com.shop.common.log.enums.BusinessType;
import com.shop.common.security.annotation.RequiresPermissions;
import com.shop.storage.domain.WmsSupplier;
import com.shop.storage.service.IWmsSupplierService;
import com.shop.common.core.web.controller.BaseController;
import com.shop.common.core.domain.Result;
import com.shop.common.core.utils.poi.ExcelUtil;


/**
 * 供应商Controller
 *
 * @author czb
 * @date 2024-06-26
 */
@RestController
@RequestMapping("/supplier")
public class WmsSupplierController extends BaseController
{
    @Autowired
    private IWmsSupplierService wmsSupplierService;

/**
 * 查询供应商列表
 */
@RequiresPermissions("storage:supplier:list")
@GetMapping("/list")
    public Result list(WmsSupplier wmsSupplier)
    {
        startPage();
        List<WmsSupplier> list = wmsSupplierService.selectWmsSupplierList(wmsSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商列表
     */
    @RequiresPermissions("storage:supplier:export")
    @Log(title = "供应商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsSupplier wmsSupplier)
    {
        List<WmsSupplier> list = wmsSupplierService.selectWmsSupplierList(wmsSupplier);
        ExcelUtil<WmsSupplier> util = new ExcelUtil<WmsSupplier>(WmsSupplier.class);
        util.exportExcel(response, list, "供应商数据");
    }

    /**
     * 获取供应商详细信息
     */
    @RequiresPermissions("storage:supplier:query")
    @GetMapping(value = "/{supplierId}")
    public Result getInfo(@PathVariable("supplierId") Long supplierId)
    {
        return success(wmsSupplierService.selectWmsSupplierBySupplierId(supplierId));
    }

    /**
     * 新增供应商
     */
    @RequiresPermissions("storage:supplier:add")
    @Log(title = "供应商", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody WmsSupplier wmsSupplier)
    {
        return toAjax(wmsSupplierService.insertWmsSupplier(wmsSupplier));
    }

    /**
     * 修改供应商
     */
    @RequiresPermissions("storage:supplier:edit")
    @Log(title = "供应商", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody WmsSupplier wmsSupplier)
    {
        return toAjax(wmsSupplierService.updateWmsSupplier(wmsSupplier));
    }

    /**
     * 删除供应商
     */
    @RequiresPermissions("storage:supplier:remove")
    @Log(title = "供应商", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierIds}")
    public Result remove(@PathVariable Long[] supplierIds)
    {
        return toAjax(wmsSupplierService.deleteWmsSupplierBySupplierIds(supplierIds));
    }
}
